package model

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"os"
)

// DB 数据库连接
var db *sql.DB

func initDB() {
	conn, err := sql.Open("mysql", "root:root@tcp(localhost:3306)/message-center")
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(-1)
	}
	defer conn.Close()

	err = conn.Ping()
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(-1)
	}

	db = conn
}
